﻿namespace RayDen.Library.Core.Primitives
{
    public class AccumulatedSpectrum
    {
        protected RgbSpectrum rgbAcc;
        protected SampledSpectrum spAcc;
        protected bool storeInRgb;

        public RgbSpectrum Result
        {
            get
            {
                if (storeInRgb)
                {
                    return this.rgbAcc;
                }
                return this.spAcc.ToRgb();
            }
        }

        public AccumulatedSpectrum(bool rgb)
        {
            storeInRgb = rgb;
        }

        public AccumulatedSpectrum Add(ref RgbSpectrum rgb, SpectrumType t)
        {

            if (storeInRgb)
            {
                this.rgbAcc += rgb;
            }
            else
            {
                this.spAcc += new SampledSpectrum(ref rgb, t);
            }

            return this;
        }

        public AccumulatedSpectrum Add(ref SampledSpectrum sp)
        {
            if (storeInRgb)
            {
                this.rgbAcc += sp.ToRgb();
            }
            else
            {
                this.spAcc += sp;
            }
            return this;            
        }

        public AccumulatedSpectrum Mul(ref RgbSpectrum rgb, SpectrumType t)
        {
            if (storeInRgb)
            {
                this.rgbAcc *= rgb;
            }
            else
            {
                this.spAcc *= new SampledSpectrum(ref rgb, t);
            }
            return this;

        }

        public AccumulatedSpectrum Mul(ref SampledSpectrum sp)
        {
            if (storeInRgb)
            {
                this.rgbAcc *= sp.ToRgb();
            }
            else
            {
                this.spAcc *= sp;
            }
            return this;     
        }


        
        
    }
}